<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <hr />
            <p>父:</p>
            <!-- <p>礼物: {{liwu}}</p> -->
            <p>礼物1: {{liwuObj.liwu1}}</p>
            <p>礼物2: {{liwuObj.liwu2}}</p>
            <child @handlewatch="fromChild"></child>
        </div>
        <!-- 定义子组件 -->
        <template id="child">
            <div>
                <hr />
                <p>Child:</p>
                <button @click="toParent">按钮</button>
            </div>
        </template>
        <script src="../vue.js"></script>
        <script>
            let child = {
                template: '#child',
                data() {
                    return {
                        watch: '劳力士',
                        watch2: '劳力士2',
                        list: {
                            liwu1: '劳力士',
                            liwu2: '海景别墅',
                        },
                    };
                },
                methods: {
                    toParent() {
                        this.$emit('handlewatch', this.watch, this.watch2);
                        // this.$emit('handlewatch', this.list);
                    },
                },
            };
            new Vue({
                el: '#app',
                data() {
                    return {
                        liwu: '',
                        liwuObj: {},
                    };
                },
                components: {
                    child,
                },
                methods: {
                    fromChild(val, val2) {
                        // this.liwu = val;
                        // this.liwuObj = val;
                        console.log(val, val2);
                    },
                },
            });
        </script>
    </body>
</html>
